# -*- coding:utf-8 -*-
import redis
from flask import Flask
from flask_migrate import MigrateCommand, Migrate
from flask_script import Manager
from flask_session import Session
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import CSRFProtect

from info import create_app, db

app = Flask(__name__)

# class Config(object):
#     """工程配置信息"""
#     DEBUG = True
#     SECRET_KEY = "2Iea7kfZlk23+fx5kLhxXyz2tqXkjj5TWqhsWTAQErQ+IZSX+K7bVRdXuE3siIge"
#     """工程配置信息"""
#     DEBUG = True
#
#     # 数据库的配置信息
#     SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/python3_flask"
#     SQLALCHEMY_TRACK_MODIFICATIONS = False
#
#     # redis配置
#     REDIS_HOST = "127.0.0.1"
#     REDIS_PORT = 6379
#
#     # flask_session的配置信息
#     SESSION_TYPE = "redis"  # 指定 session 保存到 redis 中
#     SESSION_USE_SIGNER = True  # 让 cookie 中的 session_id 被加密签名处理
#     SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT)  # 使用 redis 的实例
#     PERMANENT_SESSION_LIFETIME = 86400  # session 的有效期，单位是秒

# app.config.from_object(Config)
# db = SQLAlchemy(app)
# redis_store = redis.StrictRedis(host=Config.REDIS_HOST, port=Config.REDIS_PORT)
# CSRFProtect(app)
# Session(app)


# 调用工厂方法，创建app
app = create_app('dev')

# 添加扩展命令行
manager = Manager(app)

# 数据库迁移
Migrate(app, db)
manager.add_command('db', MigrateCommand)


if __name__ == '__main__':
    # print(app.url_map)
    # app.run(debug=True)
    manager.run()